package com.neoharvest.smartagri.observer.impl;

import com.neoharvest.smartagri.observer.EnvironmentObserver;
import com.neoharvest.smartagri.observer.EnvironmentSensor;

import java.util.ArrayList;
import java.util.List;

public class SoilMoistureSensor implements EnvironmentSensor {
    private List<EnvironmentObserver> observers = new ArrayList<>();
    private double moistureLevel;

    public void setMoistureLevel(double moistureLevel) {
        this.moistureLevel = moistureLevel;
        notifyObservers();
    }

    @Override
    public void addObserver(EnvironmentObserver observer) {
        observers.add(observer);
    }

    @Override
    public void removeObserver(EnvironmentObserver observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (EnvironmentObserver observer : observers) {
            observer.update("Soil Moisture", moistureLevel);
        }
    }
}